package demo1;

public class Test4 {
    //判断是否回文
    public static boolean Palindrome(String str) {
        str = str.toLowerCase();
        for (int i = 0, j = str.length() - 1; i <= j;) {
                if (!isletter(str.charAt(i))) {
                    while ((i <= j) && (!isletter(str.charAt(i)))) {
                        i++;
                    }
                }
                if (!isletter(str.charAt(j))) {
                    while ((i <= j) && (!isletter(str.charAt(j)))) {
                        j--;
                    }
                }
                if (str.charAt(i) == str.charAt(j)) {
                    i++;
                    j--;
                }else {
                    return false;
                }
        }

        return true;
    }
    public static boolean isletter(char ch) {
        if (ch > '0' || ch < '9') {
            return true;
        }
        if (ch > 'a' || ch < 'z') {
            return true;
        }
        return false;
    }
    public static void main(String[] args) {
        System.out.println(Palindrome("1f2abcdwdcba2f1"));
    }
}
